using System;
using System.Windows;
using System.Windows.Browser;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using JustinAngelNet.SilverlightRTL.RTL;

namespace SilverlightRTL.QuickStart
{
    [Scriptable]
    public partial class RTLExtenderPage : Canvas
    {
        public RTLExtenderPage()
        {
            this.Loaded += new EventHandler(RTLExtender_Loaded);
        }

        public void btn1_MouseLeftButtonDown(object sender, MouseEventArgs e)
        {
            Timeline1.Stop();
            Timeline1.Begin();
        }


        void RTLExtender_Loaded(object sender, EventArgs e)
        {
            InitializeComponent();

            WebApplication.Current.RegisterScriptableObject("page", this);
        }
        [Scriptable]
        public void SetTextBlockText(string text)
        {
            foreach (TextBlock key in RTLExtender.RTLTextBlockForNonRTLTextBlock.Keys)
            {
                if (key.Name == "tbx4")
                {
                    foreach (TextBlock block in RTLExtender.RTLTextBlockForNonRTLTextBlock[key])
                    {
                        this.Children.Remove(block);
                    }      
                }
            }


            TextBlock originalTextBlock = (TextBlock)XamlReader.Load(@"<TextBlock xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" Width=""540.5"" Height=""475"" Canvas.Left=""31"" Canvas.Top=""68"" TextWrapping=""Wrap"" x:Name=""tbx4"" FontFamily=""Courier New"" FontSize=""13"" FontWeight=""Bold"" />");
            originalTextBlock.Text = text.Replace("\r\n", "\r");
            this.Children.Add(originalTextBlock);

            RTLExtender rtlExtenderOnPage = (RTLExtender)FindName("rtlExtender");

            rtlExtenderOnPage.RTLTextBlock(originalTextBlock);
        }

    }
}
